Skip to content

Handle reverse conditions in isOppositeCond function#8408

Open
francois-berder wants to merge 2 commits intodanmar:mainfrom
francois-berder:reverse-cond
Open

Handle reverse conditions in isOppositeCond function#8408
francois-berder wants to merge 2 commits intodanmar:mainfrom
francois-berder:reverse-cond

Conversation

@francois-berder
Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Francois Berder <fberder@outlook.fr>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 5, 2026

static bool isZeroBoundCond(const Token * const cond, bool reverse)
{
if (cond == nullptr)
if (cond == nullptr || cond->astOperand1() == nullptr || cond->astOperand2() == nullptr)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (cond == nullptr || cond->astOperand1() == nullptr || cond->astOperand2() == nullptr)
if (cond == nullptr || !cond->isBinaryOp())

return !isZero;
if (cond->str() == ">")

if ((reverse && !cond->astOperand1()->hasKnownIntValue()) || (!reverse && !cond->astOperand2()->hasKnownIntValue()))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm an alternative that would lead to less "hard coding" would be:

    std::string cmp = cond->str();
    if (reverse && cmp[0] == '>')
        cmp[0] = '<';
    else if (reverse && cmp[0] == '<')
        cmp[0] = '>';
    const Token* const op1 = reverse ? cond->astOperand1() : cond->astOperand2();
    const Token* const op2 = reverse ? cond->astOperand2() : cond->astOperand1();

    ....

@firewave
Copy link
Copy Markdown
Collaborator

firewave commented Apr 9, 2026

Please file a ticket for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants